<script>
    var arr = [1, 2, 7, 9, 6, 3, 4, 5, 8, 9, 6, 1, 2, 45, 6, 9, 87, 45, 12]
    var newArr = []
    var newArr0 = [];
    var count = 0;

    function getNewarr(arr) {
        for (var i = 0; i < arr.length; i++) {
            newArr.push(arr[i]);
            count++;
            if (count % 5 == 0) {
                newArr0.push(newArr)
                newArr = []
            }
        }
        return newArr0;
    }
    console.log(getNewarr(arr));
</script>